from typing import Dict, List, Optional, Tuple
from instruction_re.core.datatypes import Instance, Preffix, Relation
from formatters.instances.TypeExtractFormatter import TypeAnswerFormatter
from instruction_re.formatters.instances import InstanceFormatter
from instruction_re.formatters.format_utils import *


class RelTypeNoOptionsFormatter(InstanceFormatter):
    """
    Task: Given sentence, extract the relation in the sentence
    """

    def format_data_sample(
        self,
        data_item,
        instruction: str,
    ) -> Dict:
        sentence = data_item["sentence"]
        relations = data_item["relations"]

        instruction = add_instruction_prefix(instruction)
        sentence = add_sentence_prefix(sentence)

        answer_format = TypeAnswerFormatter.from_relations(relations)

        return {
            "instruction": instruction,
            "context": sentence + " " + Preffix.ANSWER.value,
            "labels": answer_format,
        }
